all files / src/validators/ battle.validator.ts

33.33% Statements 6/18
0% Branches 0/6
0% Functions 0/4
35.29% Lines 6/17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41                                                                     
import { Action } from '../game.actions';
import { Game, Battle, Suit, Card, Phase } from '../game.interfaces';
import { getNextTrickTurn, isTrumpAnnounced, getTrumpSuit, isTableEmpty, getLeadCard, getPlayerByTrickCard } from '../helpers/battle.helpers';
import * as _ from 'lodash';
import { getCardsByColor, getCardWithHighestRank } from '../helpers/cards.helpers';
 
export function canThrowCard(state: Game, throwCard: Action) {
 
    if (state.phase !== Phase.TRICK_IN_PROGRESS) { return false; }
    
    const battle: Battle = state.battle;
    const nextTrickPlayerTurn = getNextTrickTurn(state);
 
    if (isTableEmpty(battle)) {
        //it will be first card on table
        if(isTrumpAnnounced(battle)) {
            const trumpSuit: Suit = getTrumpSuit(battle);
            //Q&K announced here
        } else {
            //ordinary card throw
        }
    } else {
        const leadCard = getLeadCard(battle);
        //upcomming cards should be related to lead card
    }
    //TODO fill logic
    return true;
}
 
export function isTrickFinished(state: Game): boolean {
    return state.battle.trickCards.length === 3;
}
 
export function isBattleFinished(state: Game): boolean {
    return _.chain(state.battle.wonCards)
        .reduce((total: number, playerCards: Card[]) => total + playerCards.length, 0)
        .isEqual(24)
        .value()
}